(require 'cl)
;------ For emacs 24, remove make-local-hook------------
(defalias 'make-local-hook
    'ignore)

;------ system setting --------------------------------
(mouse-avoidance-mode 'animate)
(setq default-major-mode 'text-mode)
(column-number-mode 1)
(tool-bar-mode -1) 
(menu-bar-mode -1)
(setq mark-even-if-inactive nil)
(setq inhibit-startup-message t)
(setq buffer-save-without-query t)
(fset 'yes-or-no-p 'y-or-n-p)
(setq frame-title-format "emacs@%b")
(put 'narrow-to-region 'disabled nil)
(put 'narrow-to-page 'disabled nil)
(scroll-bar-mode 0)
(setq display-time-24hr-format t)
(let ((system-time-locale "C"))
  (format-time-string "%a")) 
(display-time-mode t)
(show-paren-mode -1)
(autoload 'ansi-color-for-comint-mode-on "ansi-color" nil t) 
(add-hook 'shell-mode-hook 'ansi-color-for-comint-mode-on t) 
;; (my-maximized) ; 启动时最大化

;------ Backup files ----------------------------------
(setq version-control t)
(setq kept-old-versions 5)
(setq gdb-show-main t)
(setq kept-new-versions 10)
(setq delete-old-versions t)
(setq backup-directory-alist '(("." . "~/.emacs.d/.Backup")))
(setq backup-by-copying t)
(setq scroll-margin 3
      scroll-conservatively 10000)
(setq mouse-yank-at-point t)
(setq-default ispell-program-name "aspell")

;------ Compile message setting -----------------------------
(setq compilation-finish-functions
      (lambda (buf str)
        (when (and (string= (buffer-name buf) "*compilation*")
                   (not (string-match "exited abnormally" str)))
          (run-at-time 0.5 nil 'delete-windows-on buf)
          )))
(setq compilation-window-height 15)
(setq compilation-auto-jump-to-first-error t)
(setq compilation-scroll-output t)

;------ Plugins: session, ibuffer, tabbar, ido, and dired ----
;; session
(require 'session)
(add-hook 'after-init-hook 'session-initialize)
(setq session-save-file "~/.session")
(setq desktop-globals-to-save '(desktop-missing-file-warning))
(load "desktop")
(desktop-save-mode 1)
;; ibuffer
(require 'ibuffer)
(global-set-key (kbd "C-x C-b") 'ibuffer)
(add-hook 'ibuffer-mode-hook
            (lambda ()
              (setq ibuffer-filter-groups
                    '(
                      ("latex" (mode . latex-mode))
		      ("org" (mode . org-mode))
		      ("fortran" (or (mode . fortran-mode)
				     (mode . f90-mode)))
		      ("*buffer*" (name . "\\*.*\\*"))
;                      ("TAGS" (name . "^TAGS\\(<[0-9]+>\\)?$"))
                      ("dired" (mode . dired-mode))
		      ("elisp" (or (mode . emacs-lisp-mode)
                                   (mode . lisp-interaction-mode)))
                      ))))
;; tabbar
;; (require 'tabbarsetup)
;; ido
(require 'ido)
(ido-mode t)
;; dired-x
(require 'dired-x)
 (setq auto-mode-alist
            (append
             ;; File name (within directory) starts with a dot.
             '(("\\.inc\\'" . fortran-mode))
             auto-mode-alist))

(provide 'startup)

